package com.oocl.euc.core.maintenance.controller;

import com.oocl.euc.core.maintenance.model.TeamEndorser;
import com.oocl.euc.core.maintenance.service.TeamEndorserService;
import com.oocl.euc.framework.base.controller.RESTController;
import com.oocl.euc.framework.base.service.BaseService;
import com.oocl.euc.framework.common.utils.ResponseEntityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
@RequestMapping("/rest/teamEndorser")
public class TeamEndorserController extends RESTController<TeamEndorser, Long> {

    @Autowired
    TeamEndorserService teamEndorserService;

    @Override
    protected BaseService<TeamEndorser, Long> getBaseService() {
        return teamEndorserService;
    }

    @RequestMapping(value = "/displayName", method = RequestMethod.GET)
    public ResponseEntity getDisplayName(@RequestParam("teamId") Long teamId) {
        return ResponseEntityUtil.successInRestful(teamEndorserService.findDisplayName(teamId));
    }

    @RequestMapping(value = "/addTeamEndorserWithTeamAndEndorser", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity addTeamEndorserWithTeamAndEndorser(@RequestBody Map<String, Object> params) {
        String teamName = (String) params.get("teamName");
        String endorser = (String) params.get("endorser");
        return ResponseEntityUtil.successInRestful(teamEndorserService.addTeamEndorserByTeamNameAndEndorser(teamName, endorser));
    }
}
